Thread: scanf with a / character.

  1. #1
    Registered User
    Join Date
    Apr 2013
    Location
    Still looking..
    Posts
    35

    Question scanf with a / character.

    When I input 1/2 , the printf will be 1 and 2. ( Correct )

    When I input 1 / 2, the printf will be 1 and 112.

    Why ? Doesn't scanf ignore whitespace characters ?

    Thanks.

    Code:
    int main(void)
    {
        int a,b;
        
        printf("Enter 2 integers:");
        scanf("%d/%d", &a, &b);
        
        printf("This are what you entered: %d and %d",a,b);
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Krabiki View Post
    Why ? Doesn't scanf ignore whitespace characters ?
    Not if you explicitly tell you want to parse two ints separated by a slash.
    try
    Code:
    scanf("%d / %d", &a, &b);
    Kurt

  3. #3
    Registered User
    Join Date
    Apr 2013
    Location
    Still looking..
    Posts
    35
    All okay thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I delimit a single character with scanf?
    By alex3064 in forum C Programming
    Replies: 6
    Last Post: 11-30-2012, 02:06 AM
  2. Reading a space character using scanf
    By eleceng16 in forum C Programming
    Replies: 6
    Last Post: 04-26-2012, 10:46 AM
  3. scanf returns random character
    By giannisapi in forum C Programming
    Replies: 3
    Last Post: 06-20-2009, 12:06 PM
  4. Character literals in scanf
    By DL1 in forum C Programming
    Replies: 11
    Last Post: 08-09-2008, 02:36 PM
  5. change character while in scanf
    By Beginnerinc in forum C Programming
    Replies: 1
    Last Post: 05-29-2003, 11:43 AM